package cn.hesion.designpattern.Factory.SingleFactory;

import cn.hesion.designpattern.Factory.ICource;

public class CourceFactory {
    //改进工厂使用反射
    public ICource create(String classname){
        try {
            if (!(null== classname || "".equals(classname))){
                return (ICource) Class.forName(classname).newInstance();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    public ICource create(Class<? extends ICource> clazz){
        try{
            if(null != clazz){
                return clazz.newInstance();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
